package com.hyz.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hyz.pojo.User;
import com.hyz.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author HGD
 * @date 2022/10/5 12:28
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService service;

    @PostMapping("/getDepartmentIddById")
    public Long getDepartmentIddById(@RequestBody Long id) {
        return service.getById(id).getDepartmentId();
    }

    @PostMapping("/getIdsByDepartmentId")
    public List<Long> getIdsByDepartmentId(@RequestBody Long departmentId) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(User::getDepartmentId, departmentId)
                .select(User::getId);
        List<Long> ids = new ArrayList<>();
        for (User user : service.list(wrapper)) {
            ids.add(user.getId());
        }
        return ids;
    }
}
